package com.atguigu02.singleton;

/**
 * ClassName: BankTest
 * Package: com.atguigu02.singleton
 * Description:
 *       饿汉式：“立即加载”,随着类的加载，当前的唯一实例就创建了
 * @Author xiao_qi
 * @Create 2024/9/2 21:11
 * @Version 1.0
 */
public class BankTest {
    public static void main(String[] args) {
        bank b1 = bank.getInstance();
        bank b2 = bank.getInstance();

        System.out.println(b1 == b2);
    }

}
class bank{
    //1.私有化构造器
    private bank(){}

//    2. 在类的内部创建当前类的实例
//4. 此属性也必须声明为static的
    private static bank instance = new bank();

    //3. 使用getXxx()方法获取当前类的实例，必须声明为static的
    public static bank getInstance(){
        return instance;
    }
}

